$('#loginSubmit').on('click', function () {
  axios({
    method: 'post',
    url: 'https://api.nevegy.com/index.php/api/manage?mtd=Login',
    data: {
      user: $('#username').val(),
      password: $('#pwd').val()
    }
  })
    .then(function (response: any) {
      if (Number(response.data.code) === 200) {
        console.log(response);
        localStorage.setItem('token', response.data.data.token);
        let locs = response.data.data.lists.map((item: any) => item.locationId);
        localStorage.setItem('locs', JSON.stringify(locs));
        window.location.href = getHtml();
      }
    });
})

function getHtml() {
  let params: any = localStorage.getItem('urlParma');
  params = JSON.parse(params);
  let html = params.html;
  delete params.html;
  let path = params.path;
  delete params.path;
  let param = Object.keys(params).map(key => key + '=' + params[key]).join('&');
  param = path + html + '?edit=update&' + param + '&u=' + $('#username').val() + '&p=' + $('#pwd').val();
  return param;
}

